<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/commons/include/html_doctype.html"%>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <%@include file="/commons/page/codegen.jsp"%>
    <link href="${ctx}/js/gpoint/rdp/zone/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${ctx}/js/gpoint/rdp/zone/css/bootstrap-duallistbox.min.css" rel="stylesheet" />
    
   <script src="${ctx}/js/gpoint/rdp/zone/jquery-3.0.0.min.js"></script>
    <script src="${ctx}/js/gpoint/rdp/zone/bootstrap.min.js"></script>
    <script src="${ctx}/js/gpoint/rdp/zone/jquery.bootstrap-duallistbox.js"></script>
       <link type="text/css" rel="stylesheet" href="${ctx}/js/gpoint/rdp/zone/css/bootstrap.css">

<script type="text/javascript" src="${ctx}/js/gpoint/rdp/zone/bootstrap-paginator.js"></script>
<script type="text/javascript" src="${ctx}/js/gpoint/rdp/TimeSegment/timeSeg.js"></script>
</head>

<body>

<div class="panel panel-default">
    <div class="panel-heading">
      <!--   不带 title 的面板标题 --> 权限类型选择
    </div>
    <div class="panel-body">
     <!--    面板内容 -->
	 <div class="toolbar-body" >
	      
						<form role="form" class="search-form">
						  
							<div  class="form-inline p-xxs">	
							    <div class="form-group">
										  权限类型<select id="permissionProperty" onchange="permissionselect()" > 

										   </select> 
								</div>
														
									
								
								<div class="form-group">
										 <a id="showValue3" class="btn btn-primary fa fa-search" href="javascript:void(0);" ><span>允许</span></a>
										 <a id="showValue4" class="btn btn-primary fa fa-search" href="javascript:void(0);" ><span>取消</span></a>
								</div>								
							</div>
						</form>
					</div><!--/ 查询条件-->
    </div>
</div>
 
 

   <div class="row" >
        <div class="col-lg-6 " >
		        <div class="panel panel-default">
				    <div class="panel-heading">
				        用户选择
				    </div>
				    <div class="panel-body">
										       <div class="col-md-12">
				
								
						        <select multiple="multiple" size="10" name="duallistbox_demo1" class="demo1">
						        </select>
						       
						       <ul class="pagination"  id="page"></ul>
						                    </div>
    
				    </div>
				</div>

        </div>
        <div class="col-lg-6 ">
		        <div class="panel panel-default" >
					    <div class="panel-heading">
					         门选择
					    </div>
					    <div class="panel-body" style="height:530px;" >
								     <div class="col-md-12"  >
											       <table class="table" id="tablePlanDetail">
											       
									<tr>
										<td>
											<label>区域</label>
										</td>
										<td>
										      <input name="m:doorController:zoneid" type="hidden"   id="hid_zoonid" value="${doorController.zoneid}"/>						    					
								    <input type="text" data-key="#hid_zoonid" readonly="readonly"  class="form-control comboTree" data-toggle="dictionary" data-url="${ctx}/rdp/area/zone/list_json_tree.htm?" value="${doorController.zonename}"  validate="{required:true}"/>
										</td>
									      
									
							         </tr>
										
									</tr>
									
														<tr>
															
															<td>
																  时间段<select id="datasetProperty" onchange="cge()">  </select>
															</td>
															<td>
																  <button  onclick="queryctl()" > 查询 </button>
															</td>
														</tr>
													</table>
											        <select multiple="multiple" size="10" name="duallistbox_demo2" class="demo2">
											        </select>
				      
											         <ul  class="pagination"  id="page"></ul>
											    </div>
						            </div> 
						            
						            
						               
						                    
						                    
						                    
				</div>

        </div>
    </div>

 </div>
 
 


  
 
 


    
    
 
</body>



<script type="text/javascript">

 <%--  var __ctx = '<%=path%>'; --%>
function appendHtml(returnData) {//此函数用于处理后台返回的数据，根据自己需求来实现页面拼接
	  var objs = $.parseJSON( JSON.stringify(returnData));
    
      $(objs).each(function () {
         
    	  if(objs==null ){
    		  alert("用户数据获取异常！");
    		   return;
    		  
    	  }else{
    		  var objA=objs.rows;    
              for(var i=0;i<objA.length;i++){
             	  var o = document.createElement("option");
             	 
             	 // alert(objA[i]['test']);
             	   o.value = objA[i]['carduid']+","+objA[i]['username'];
             	  
             
                  o.text =  objA[i]['carduid']+","+objA[i]['username'];
                //  o.text =  "001 &nbsp;  "+"|"+"    &nbsp;   56789      |"+"  &nbsp;  |"+"abcdc  " ;
                //	  o.value = objA[i]['test'];
                 //o.text = objA[i]['test'] ;
               //  alert(o.text);
                 $("." + 'demo1' + "")[0].options.add(o);
                 
                 
                 
              }
            
              $('.demo1').bootstrapDualListbox('refresh');
            
    		  
    	  }
           
      });      //渲染dualListbox
      $('.' + 'demo1' + '').bootstrapDualListbox({
          nonSelectedListLabel: '人员列表 ',
          selectedListLabel: '已选择授权人数：',
          preserveSelectionOnMove: 'moved',
          moveOnSelect: false//,
          //nonSelectedFilter: 'ion ([7-9]|[1][0-2])'
      });
      
}

var __ctx="http://127.0.0.1:8083";
function appendHtml2(returnData) {//此函数用于处理后台返回的数据，根据自己需求来实现页面拼接
	  var objs = $.parseJSON( JSON.stringify(returnData));
  
    $(objs).each(function () {
       
         var objA=objs.rows;    
         for(var i=0;i<objA.length;i++){
        	  var o = document.createElement("option");
        	  o.value = objA[i]['controllersn']+","+objA[i]['doorno'];
             o.text =  objA[i]['controllersn']+","+objA[i]['doorno'];
             $("." + 'demo2' + "")[0].options.add(o);
            
            
         }
       
         $('.demo2').bootstrapDualListbox('refresh');
       
    });      //渲染dualListbox
    $('.' + 'demo2' + '').bootstrapDualListbox({
    	  nonSelectedListLabel: '门列表',
          selectedListLabel: '已选择门数：',
          preserveSelectionOnMove: 'moved',
          moveOnSelect: false//,
    });
    
}




$(function() {
	
	//alert("分页预加载中...");
	 pageStart();//开始分页
			
	 function pageStart() {//分页函数
	    $.ajax({ //去后台查询第一页数据
			type : "get",
			url : __ctx+"/rdp/user/campusCard/listJson",
			dataType : "json",
			data : {page : '1'}, //参数：当前页为1
			success : function(data) {
					
				
				//需要增加异常处理
				
			  appendHtml(data);//处理第一页的数据
				
			  var options = {//根据后台返回的分页相关信息，设置插件参数
				bootstrapMajorVersion : 3, //如果是bootstrap3版本需要加此标识，并且设置包含分页内容的DOM元素为UL,如果是bootstrap2版本，则DOM包含元素是DIV
				currentPage : data.page, //当前页数
				totalPages : data.total, //总页数
				numberOfPages : 20,//每页记录数
				itemTexts : function(type, page, current) {//设置分页按钮显示字体样式
					switch (type) {
					case "first":
						return "首页";
					case "prev":
						return "上一页";
					case "next":
						return "下一页";
					case "last":
						return "末页";
					case "page":
						return page;
					}
				},
			  onPageClicked : function(event, originalEvent, type, page) {//分页按钮点击事件
				
				$.ajax({//根据page去后台加载数据
					url : __ctx+"/rdp/user/campusCard/listJson",
					type : "get",
					dataType : "json",
					data : {"page" : page,"rows":20},
					success : function(data) {
						
						  $("." + 'demo1' + "").empty();
						  
							/*   $('.demo1').bootstrapDualListbox({
									
								  removeAllLabel: '移除全部option',//移除全部option按钮的label，默认'Remove all'
								  
								}); */
							//  $("." + 'demo1' + "")[0].options.remove();
							   $('.demo1').bootstrapDualListbox('removeSelectedLabel');
							 //  $('.demo1').bootstrapDualListbox('setMoveAllLabel', "");
							   $('.demo1').bootstrapDualListbox('setMoveAllLabel','', true);
							 //  $('.demo1').bootstrapDualListbox('destroy');
							 
							 
						appendHtml(data);//处理数据
				     
					}
				});
			  }
		    };
			$('#page').bootstrapPaginator(options);//设置分页
			}
		});
	}
	 
	 
	
	 
	 
	  
	});
	
	
	

function a(caruid){
	  var strs = new Array(); //定义一数组
	  
	   strs =  String(caruid).split(","); //字符分割

	  
	   var b=[];
	   for (i=0; i<strs.length; i++ ){
	        
		   if(i%2==0){  
			   if(i==0){
				  
				   b.push(String (strs[i])+","+strs[i+1]+"|");
			   }else{
				 
				  
				   b.push(String (strs[i])+","+strs[i+1]+"|");
			   }
			   
		   }
	   }
	   console.log(b);
	   return b;
	  //end
}



	
	var selectvalue;
	var permissonselect; //权限类型选择数值
/* 
	var index; //时间框控件选择数值
	var selectvalue; */
$("#showValue3").click(function () {
	//alert("授权进行");
	//得到第一个列表
       
	 //
	   var caruid=$('[name="duallistbox_demo1"]').val();
	 //  alert("carduid="+caruid);
	  //截取字符串分组
	    b= a(caruid);
	   
	//  alert(b);
	//得到门列表
	  var doorlist=$('[name="duallistbox_demo2"]').val(); 
	  
	//  alert("doorlist="+doorlist);
	   c= a(doorlist);
	//  alert(c);
	  
	 
	//  alert(selectvalue);
	  
	  
	  //得到下拉框的数值
	 var permissionindex=$("#permissionProperty").val();  
	  
	  
	//1.判断为空，必须填完才能进行保存，不能进行类型授权操作：
		if(caruid.length!=0 && doorlist.length!=0){

			 //拼成JSON数组传递
			   var str = [];
				    		   var userArr= b; //id，卡号，姓名
				    		  // var doorArr = ["111","222"]; //控制器SN号，门号
				    		   var doorArr = c; //控制器SN号，门号
				    		   
				   //3.用户权限
				    		  var map ={};
				    		   map.useArr = userArr;
		    		    	   map.startTime=permissonselect;   //用户选择类型
		    		    	   
				    		   $.ajax({
		    		    	         	type: "post",
		    		    	         	   url: __ctx+"/rdp/doorPermission/permissTypeAndUser/save3",
		    		    	         	    contentType: "application/json;charset=utf-8;",
		    		    	         	  data:JSON.stringify(map),
		    		    	         	  dataType:"json",//注意不是datatype哦
		    		    	         	    async: false,//使用同步操作，否则init方法执行时setting可能还未被赋值
		    		    	         	   success: function(data) {
		    		    	         	          alert("绑定用户权限类型成功！");
		    		    	         	  },
		    		    	         	 error: function(){
		    		    	         		  alert("绑定用户权限类型失败！");
		    		    	              }
		    		    	         	 
		    		    	         	 }); 
		    		    	         	 //end
		 
		    
		    		    	         	
		    		    	     map.doorArr = doorArr; //门列表 和时间段
		    		    	     map.endTime=selectvalue; //门的类型
		    		    	         	 
		    	//4.存入doorpremisson
		    	 $.ajax({
		    		    	         	type: "post",
		    		    	         	   url: __ctx+"/rdp/doorPermission/doorPermissonType/save3",
		    		    	         	    contentType: "application/json;charset=utf-8;",
		    		    	         	  data:JSON.stringify(map),
		    		    	         	  dataType:"json",//注意不是datatype哦
		    		    	         	    async: false,//使用同步操作，否则init方法执行时setting可能还未被赋值
		    		    	         	   success: function(data) {
		    		    	         	          alert("绑定门权限类型成功！");
		    		    	         	  },
		    		    	         	 error: function(){
		    		    	         		  alert("绑定门权限类型失败！");
		    		    	              }
		    		    	         	 
		    		    	         	 }); 
		    		    	         	 //end
			
			
		}else{
			alert("必须填完才能进行保存，不能进行类型授权操作");
		}
	  
	  
     
});





//下拉栏表框初始化初始化      
//初始化赋值
$(function () {
    //初始化时间段控件
    initList('hangwei.cnblogs.com', 'demo1');
    initPermissionType('hangwei.cnblogs.com', 'demo1');
 
 
});


function initList(queryParam1,selectClass, selectedDataStr) {
    var paramData = {
        'testParam1': queryParam1
    }
    $.ajax({
        url: __ctx+"/rdp/TimeSegment/timeSeg/listJson",
        type: 'get',
        data: paramData,
        async: false,
        success: function (returnData) {
            var objs = $.parseJSON( JSON.stringify(returnData));
           var objA=objs['rows'];     //大数量下载失败   
          var html = "";
           $('#datasetProperty').append("<option value='0'>--任意时间有效--</option>");
            for (var i in objA) {
            	html += '<option value=' + objA[i].timeseg + '>' + objA[i].timeseg + '</option>'
            }
            $("#datasetProperty").append(html); //渲染
        },
        error: function (e) {
            alert(e.msg);
        }
    });
}

//权限类型初始化
function initPermissionType(queryParam1,selectClass, selectedDataStr) {
    var paramData = {
        'testParam1': queryParam1
    }
    $.ajax({
        url: __ctx+"/rdp/doorPermission/permissionTypes/listJson",
        type: 'get',
        data: paramData,
        async: false,
        success: function (returnData) {
        	console.log(returnData);
            var objs = $.parseJSON( JSON.stringify(returnData));
           var objA=objs['rows'];     //大数量下载失败   
          var html = "";
           $('#permissionProperty').append("<option value='0'>--请选择权限类型--</option>");
            for (var i in objA) {
            	html += '<option value=' + objA[i].permissionid + '>' + objA[i].permissionid + '</option>'
            }
            $("#permissionProperty").append(html); //渲染
        },
        error: function (e) {
            alert(e.msg);
        }
    });
}
//下拉栏表框初始化完毕    









     
         
   //第二个列表框初始化      
        //初始化赋值
      $(function () {
            //初始化
            initListBox2('hangwei.cnblogs.com', 'demo2');

            $("#showValue2").click(function () {
             //   alert($('[name="duallistbox_demo2"]').val());
            });
        });
        /*初始化duallistbox*/
        //queryParam1：参数
        //selectClass：select元素class属性
        //selectedDataStr：选中数据，多个以,隔开
        function initListBox2(queryParam1,selectClass, selectedDataStr) {
            var paramData = {
                'testParam1': queryParam1
            }
            $.ajax({
                url: __ctx+"/rdp/door/door/getData",
                type: 'get',
                data: paramData,
                async: true,
                success: function (returnData) {
                    var objs = $.parseJSON( JSON.stringify(returnData));
                    $(objs).each(function () {
                        var o = document.createElement("option");
                        o.value = this['controllerid']+","+this['doorname'];
                        o.text = this['controllerid']+","+this['doorname'];
                        $("." + selectClass + "")[0].options.add(o);
                    });
                    //渲染dualListbox
                    $('.' + selectClass + '').bootstrapDualListbox({
                        nonSelectedListLabel: '门列表 ',
                        selectedListLabel: ' 已选择门数：',
                        preserveSelectionOnMove: 'moved',
                        moveOnSelect: false//,
                        //nonSelectedFilter: 'ion ([7-9]|[1][0-2])'
                    });
                },
                error: function (e) {
                    alert(e.msg);
                }
            });
        } 
//第二个列表框初始化完毕
      

  function cge(){
    var sel=document.getElementById('datasetProperty');
            var sid=sel.selectedIndex;
  //  alert(sel[sid].value+'-'+sel[sid].innerHTML);
     index=sel[sid].innerHTML;
  //  alert("index="+index);
    selectvalue=sel[sid].value;
     
     
     //  alert("获取选择数值="+selectvalue);
}      


  function permissionselect(){
	    var sel=document.getElementById('permissionProperty');
	            var sid=sel.selectedIndex;
	  //  alert(sel[sid].value+'-'+sel[sid].innerHTML);
	     index=sel[sid].innerHTML;
	  //  alert("index="+index);
	    selectvalue=sel[sid].value;
	  
	    permissonselect=selectvalue;
	      
	   //  alert("获取类型数值="+permissonselect);
	}
  
 ////列表框事件：
	   
  
  
  
  
 
	  
	 
	  
	  
	  //查询控制器
	  function   queryctl(){  
		     
		//  (" 查询控制器信息,请稍等...");
	   
	     //获取信息
	       var ctl= $("#ctl").val();
	       var zoneid= $("#hid_zoonid").val();
	      
	     //发送ajax请求
	       $.ajax({
        url: __ctx+"/rdp/door/door/query",
        type: 'get',
        data : {ctl : ctl,zoneid:zoneid}, //参数：当前页为1
        async: false,
        success: function (data) {
        	       console.log(data);
        	      
        	       $("." + 'demo2' + "").empty();
					  
					   $('.demo2').bootstrapDualListbox('removeSelectedLabel');
					
					   $('.demo2').bootstrapDualListbox('setMoveAllLabel','', true);
					   
					   appendHtml2(data);
        	      
        },
        error: function (e) {
            (e.msg);
        }
    });
	     //结果赋值
		      }  
	  
	  
	  
    </script>
</html>
